package work.ib.apt.complex;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class StrangeChars {

	private static final String dbClass = "com.mysql.jdbc.Driver";

	public static void main(String[] args) {
		try {
			new StrangeChars().run();
		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
	}

	private void run() {
		// Staging
		String dbUrl = "jdbc:mysql://172.16.12.27:3306/websimpl_aptrate";
		String user = "usraptratings";
		String password = "F1ndm3@g00dAPT$";

// PROD
//String dbUrl = "jdbc:mysql://10.16.128.83:3306/websimpl_aptrate";
//String user = "aptratings";
//String password = "password";


		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;

		Set<Character> set = new HashSet<Character>();
		try {
			Class.forName(dbClass);
			conn = DriverManager.getConnection(dbUrl, user,password);

			ps = conn.prepareStatement("select complex_name from aptcomplexes");

			ps.execute();
			rs = ps.getResultSet();

			while (rs.next()) {
				String name = rs.getString("complex_name");
				char[] chars = name.toCharArray();
				for (int i = 0; i < chars.length; i++) {
					set.add(chars[i]);
				}
			}

		} catch (Exception e) {
			e.printStackTrace(System.out);
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace(System.out);
				}
			}
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace(System.out);
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace(System.out);
				}
			}
		}

		List<Character> list = new ArrayList<Character>(set);
		Collections.sort(list);

		for (Character character : list) {
			System.out.println("\"" + character + "\"");
		}
	}

}
